
#include	"SysConfig.h"
#include	"Define.h"
#include	"Stdio.h"
#include	"Display.h"
#ifdef  ST7565P
#include	"ST7565P.h"
#endif
#ifdef  MOVON
#include	"Bluetooth.h"
#include	"Movon.h"
#endif
#ifdef  PHONE_BOOK
#include	"PhoneBook.h"
#endif
#ifdef  MIC
#include	"MIC.h"
#endif

#ifdef  BLUETOOTH
unsigned char ucDISP_BT_CallerID[BT_CALLERID_LEN];
unsigned char ucDISP_PBAPSearchResult;
extern BT_DEVICE	sBT_BDList[BT_DEVICE_NUM];
extern unsigned char ucBT_DeviceCnt;
extern unsigned char ucBT_LocalName[BT_LOCALNAME_SIZE];
extern unsigned char ucBT_LocalAddress[6];
extern unsigned char ucBT_PairedDeviceIndex;
extern unsigned char ucBT_CallerID[BT_CALLERID_LEN];
#endif
#ifdef  MOVON
extern MV_MIC_STATUS ucMV_MIC_Mute;
extern MV_CALL_STATUS ucMV_CallStatus;
extern unsigned char ucMV_HF_AudioConnect;
extern MV_HF_STATUS ucMV_HFS_Status;
#endif
#ifdef  PHONE_BOOK
extern unsigned char ucPBAP_SearchResult;
extern PBAP_LIST	sPBAP_List;
#endif

extern unsigned char ucDISP_Blink;
extern unsigned char ucDISP_TempPage;

#ifdef BLUETOOTH

unsigned char Bluetooth_DISP_CallNumberSize(unsigned char *ucNum, unsigned char ucSize)
{

	unsigned char i;

	for(i = 0; i < ucSize; ++i)
	{
		if  (*ucNum == 0x00)
		{
			break;
		}
		++ucNum;
	}
	return(i);
}

unsigned char Bluetooth_DISP_GetStringLentgh(unsigned char *ucBuf, unsigned char Lfn, unsigned short ucSize)
{
	unsigned short i;
	
	for(i = 0; i < ucSize; ++i)
	{
		if	(Lfn == 1)
		{
			if	((*ucBuf == 0x00) && (*(ucBuf+1) == 0x00))
			{
				break;
			}
			++i;
			++ucBuf;
			++ucBuf;
		}
		else
		{
			if	(*ucBuf == 0x00)
			{
				break;
			}
			++ucBuf;
		}
	}
	return(i);
}

void Bluetooth_DISP_IconMain(void)
{
}


void Bluetooth_DISP_Display_SubText(void)
{
	unsigned char ucBuf[3];
	
	memcpy(&ucBuf[0], "BT ", 3);		
#ifdef  ST7565P
	ST7565_UpdateSubDisplayData(&ucBuf[0]);
#endif

}

void BT_LPB_DISP_SubText(void)
{
	unsigned char ucBuf[3];
	memcpy(&ucBuf[0], "LPB", 3);
		
#ifdef  ST7565P
	ST7565_UpdateSubDisplayData(&ucBuf[0]);
#endif
}

void BT_DISP_BtTel(void)
{
	unsigned char ucBuf[15];
	 
	memset(&ucBuf[0], 0x00, 15);
	memcpy(&ucBuf[0], "BT TEL", 6);	
	
#ifdef  ST7565P
	ST7565_UpdateDisplayString(0, &ucBuf[0], 1);
#endif

}

void BT_DISP_PhoneNumber(void)
{	
	if  ((ucDISP_TempPage > 5) && (ucPBAP_SearchResult == 1))
	{
		if  (sPBAP_List.ucCharSet == PBAP_CHAR_UTF8)
		{
		#ifdef  ST7565P
			ST7565_UpdateDisplayStringUnicode(0, &sPBAP_List.ucName[0], 0, 0xF3);
		#endif
		}
		else
		{
		#ifdef  ST7565P
			ST7565_UpdateDisplayString(0, &sPBAP_List.ucName[0], 1);
		#endif
		}
	}
	else
	{
	#ifdef  ST7565P
		ST7565_UpdateDisplayString(0, &ucBT_CallerID[0], 1);
	#endif
	}
}

void Bluetooth_DISP_Display_PhoneName(void)
{
	
#ifdef  ST7565P
	ST7565_UpdateDisplayString(0, &ucBT_LocalName[0], 0);
#endif

}

void Bluetooth_DISP_Display_Calling(void)
{
	unsigned char ucBuf[7];
	
	memcpy(&ucBuf[0], "Calling...", 10);
			
#ifdef  ST7565P
	ST7565_UpdateDisplayData(14, ucBuf[0]);
	ST7565_UpdateDisplayData(23, ucBuf[1]);
	ST7565_UpdateDisplayData(31, ucBuf[2]);
	ST7565_UpdateDisplayData(34, ucBuf[3]);
	ST7565_UpdateDisplayData(37, ucBuf[4]);	
	ST7565_UpdateDisplayData(40, ucBuf[5]);
	ST7565_UpdateDisplayData(47, ucBuf[6]);
	ST7565_UpdateDisplayData(54, ucBuf[7]);
	ST7565_UpdateDisplayData(57, ucBuf[8]);
	ST7565_UpdateDisplayData(60, ucBuf[9]);	
#endif
	
}

void BT_DISP_Private(void)
{
	unsigned char ucBuf[15];
	 
	memset(&ucBuf[0], 0x00, 15);
	memcpy(&ucBuf[0], "BT PRIVATE", 10);
		
#ifdef  ST7565P
	ST7565_UpdateDisplayString(0, &ucBuf[0], 1);
#endif

}

void BT_DISP_MicMute(void)
{
	unsigned char ucBuf[8];

	memcpy(&ucBuf[0], "MIC MUTE", 8);
	
	if  (ucDISP_Blink == 0)
	{
	#ifdef ST7565P
		ST7565_UpdateDisplayData(7, ucBuf[0]);
		ST7565_UpdateDisplayData(18, ucBuf[1]);
		ST7565_UpdateDisplayData(21, ucBuf[2]);
	
		ST7565_UpdateDisplayData(35, ucBuf[4]);
		ST7565_UpdateDisplayData(46, ucBuf[5]);
		ST7565_UpdateDisplayData(55, ucBuf[6]);
		ST7565_UpdateDisplayData(64, ucBuf[7]);
	#endif
	}	
}

void BTH_DISP_MainText(void)
{
#ifdef  MIC
	if	(MIC_GetMicStatus() == MIC_ON)
	{
		MIC_DISP_MainText();
		return;
	}
#endif
	if  (ucMV_MIC_Mute == MV_MIC_MUTE_ON)
	{
		BT_DISP_MicMute();
		return;
	}

	if  ((ucMV_HFS_Status == MV_HFS_INCOMING) || (ucMV_HFS_Status == MV_HFS_OUTGOING))
	{
		BT_DISP_PhoneNumber();
		return;
	}
	if  (ucMV_HF_AudioConnect == HF_AUDIO_PHONE)
	{
		BT_DISP_Private();
	}
	else
	{
		BT_DISP_BtTel();
	}
}

void BT_LPB_DISP_MainText(void)
{
	unsigned char ucBuf[15];
	 
	memset(&ucBuf[0], 0x00, 15);
	memcpy(&ucBuf[0], "LoopBack", 8);
	
#ifdef  ST7565P
	ST7565_UpdateDisplayString(0, &ucBuf[0], 1);
#endif
}

#endif
